`
https://leetcode.cn/problems/convert-bst-to-greater-tree/
`

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var convertBST = function (root) {
  let sum = 0

  // 中序逆序遍历，再让每个结点加上之前的值即可
  const traverse = (node) => {
    if (node === null) return

    traverse(node.right)

    node.val += sum
    sum = node.val

    traverse(node.left)
  }

  traverse(root)

  return root
};